home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / cstwnd / statebut.h < prev    next >
C/C++ Source or Header  |  1993-12-17  |  2KB  |  77 lines

  1. #ifndef _STATEBUT_H_
  2. #define _STATEBUT_H_
  3.  
  4. #ifndef __CONTROL_H
  5. #include <control.h>
  6. #endif
  7.  
  8. #define SB_OFF            0    //Off
  9. #define SB_ON            1    //On
  10.  
  11. _CLASSDEF(TStateButton)
  12. class _EXPORT TStateButton : public TControl
  13. {
  14. protected:
  15.     struct
  16.     {
  17.         unsigned int State    : 1;
  18.         unsigned int Focus    : 1;    //Has input focus
  19.         unsigned int Capture    : 1;    //Captured, LButton Down
  20.         unsigned int Space    : 1;    //Space bar down
  21.         unsigned int LastIn    : 1;    //Last mouse pos in control
  22.         unsigned int Changing: 1;    //State is changing
  23.     } Chars;
  24.    RECT ClientRect;
  25.  
  26.     virtual void DrawOff(HDC DrawDC);
  27.     virtual void DrawOn(HDC DrawDC);
  28.     virtual void ChangeFocus(HDC DrawDC);
  29.  
  30.     virtual LPSTR GetClassName()
  31.         {    return (LPSTR)"SBUTTON"; };
  32.     virtual void GetWindowClass(WNDCLASS& WndClass);
  33.  
  34. private:
  35.     void StateChange(void);
  36. public:
  37.     TStateButton(PTWindowsObject AParent, int AnId,
  38.         LPSTR ATitle, int X, int Y, int W, int H,
  39.         PTModule    ATModule = NULL);
  40.     TStateButton(PTWindowsObject AParent, int ResourceId,
  41.         PTModule ATModule = NULL);
  42.     virtual Config();
  43.  
  44.     virtual void SetupWindow();
  45.  
  46.     virtual void WMSetFocus(RTMessage Msg) = [WM_FIRST + WM_SETFOCUS];
  47.     virtual void WMKillFocus(RTMessage Msg) = [WM_FIRST + WM_KILLFOCUS];
  48.     virtual void WMLButtonDown(RTMessage Msg) = [WM_FIRST + WM_LBUTTONDOWN];
  49.     virtual void WMLButtonUp(RTMessage Msg) = [WM_FIRST + WM_LBUTTONUP];
  50.     virtual void WMKeyDown(RTMessage Msg) = [WM_FIRST + WM_KEYDOWN];
  51.     virtual void WMKeyUp(RTMessage Msg) = [WM_FIRST + WM_KEYUP];
  52.     virtual void WMGetDlgCode(RTMessage Msg) = [WM_FIRST + WM_GETDLGCODE];
  53.     virtual void WMMouseMove(RTMessage Msg) = [WM_FIRST + WM_MOUSEMOVE];
  54.     virtual void Paint(HDC PaintDC, PAINTSTRUCT _FAR & PaintInfo);
  55.    virtual void WMSize(RTMessage Msg) = [WM_FIRST + WM_SIZE];
  56.     virtual void WMMouseActivate(RTMessage Msg) = [WM_FIRST + WM_MOUSEACTIVATE]
  57.         {    SetFocus(HWindow); };
  58.  
  59.     void SetState(BOOL State)
  60.         { Chars.State = State;
  61.             StateChange(); };
  62.     BOOL GetState(void)
  63.        { return Chars.State; }
  64.     BOOL IsOn(void)
  65.         { return (Chars.State == SB_ON); }
  66.     BOOL IsOff(void)
  67.         { return (Chars.State == SB_OFF); }
  68.     void TurnOn(void)
  69.        { SetState(SB_ON); }
  70.     void TurnOff(void)
  71.        { SetState(SB_OFF); }
  72.     void Toggle(void)
  73.        { SetState(!Chars.State); }
  74.     
  75. };
  76.  
  77. #endif